package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author  供应商管理控制层
 * @Description:
 */
@RestController
@RequestMapping("/supplier")
public class SupplierController {

    // 注入 service
    @Autowired
    private SupplierService supplierService;

    /**
     *  分页查询供应商
     * 请求参数：Integer page（当前页数）, Integer rows（每页显示的记录数）, String supplierName
     * @param page
     * @param rows
     * @param supplierName
     * @return map集合
     */
    @PostMapping("/list")
    @ResponseBody
    public Map<String,Object> getSupplierPageList (@PathVariable Integer page, @PathVariable Integer rows,@PathVariable String supplierName) {
        return  supplierService.getSupplierPageList(page,rows,supplierName);
    }


    /**
     * 新增或者修改供应商
     * @param
     * @param supplier
     * @return
     */
    @PostMapping("save")
    @ResponseBody
    public ServiceVO saveOrUpdate(Supplier supplier){
        supplierService.saveOrUpdate(supplier);
        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS);
    }

    /**
     * 删除供应商列表支持批量删除
     * @param ids
     * @return
     */
    @PostMapping("delete")
    @ResponseBody
    public ServiceVO delete(List<String> ids){
        return supplierService.deleteById(ids);
    }


}
